home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / atan2.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  3KB  |  97 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                              N O T I C E                             *
  4.  *                                                                      *
  5.  *                      Copyright Abandoned, 1987, Fred Fish            *
  6.  *                                                                      *
  7.  *      This previously copyrighted work has been placed into the       *
  8.  *      public domain by the author (Fred Fish) and may be freely used  *
  9.  *      for any purpose, private or commercial.  I would appreciate     *
  10.  *      it, as a courtesy, if this notice is left in all copies and     *
  11.  *      derivative works.  Thank you, and enjoy...                      *
  12.  *                                                                      *
  13.  *      The author makes no warranty of any kind with respect to this   *
  14.  *      product and explicitly disclaims any implied warranties of      *
  15.  *      merchantability or fitness for any particular purpose.          *
  16.  *                                                                      *
  17.  ************************************************************************
  18.  */
  19.  
  20. /*
  21.  *  FUNCTION
  22.  *
  23.  *      atan2   double precision arc tangent of two arguments
  24.  *
  25.  *  KEY WORDS
  26.  *
  27.  *      atan2
  28.  *      machine independent routines
  29.  *      trigonometric functions
  30.  *      math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *      Returns double precision arc tangent of two
  35.  *      double precision floating point arguments ( atan(Y/X) ).
  36.  *
  37.  *  USAGE
  38.  *
  39.  *      double atan2(x,y)
  40.  *      double x;
  41.  *      double y;
  42.  *
  43.  *  REFERENCES
  44.  *
  45.  *      Fortran 77 user's guide, Digital Equipment Corp. pp B-4.
  46.  *
  47.  *  RESTRICTIONS
  48.  *
  49.  *      Note that the argument usage is exactly the reverse of the
  50.  *      common FORTRAN usage where atan2(x,y) computes atan(x/y).
  51.  *      The usage here is less confusing than remembering that x is
  52.  *      really y and y is really x.
  53.  *
  54.  *      For precision information refer to documentation of the
  55.  *      other floating point library routines called.
  56.  *      
  57.  *  PROGRAMMER
  58.  *
  59.  *      Fred Fish
  60.  *      Tempe, Az 85281
  61.  *
  62.  *  INTERNALS
  63.  *
  64.  *      Computes atan(y/x) from:
  65.  *
  66.  *              1.      If x = 0 then
  67.  *                      atan(x,y) = PI/2 * (sign(y))
  68.  *
  69.  *              2.      If x > 0 then
  70.  *                      atan(x,y) = atan(y/x)
  71.  *
  72.  *              3.      If x < 0 then atan2(x,y) =
  73.  *                      PI*(sign(y)) + atan(y/x)
  74.  *
  75.  */
  76.  
  77. #include <stdio.h>
  78. #include "pml.h"
  79.  
  80. double atan2 (x, y)
  81. double x;
  82. double y;
  83. {
  84.     double result;
  85.     extern double sign();
  86.     extern double atan();
  87.  
  88.     if (x == 0.0) {
  89.         result = sign (HALFPI, y);
  90.     } else if (x > 0.0) {
  91.         result = atan (y/x);
  92.     } else {
  93.         result = atan (y/x) + sign (PI, y);
  94.     }
  95.     return (result);
  96. }
  97.